#!/bin/bash
set -e

while getopts  ":s:p:" opts
do
	case  $opts  in
	s)
	sample_name=$OPTARG
	;;
	p)
	out_prefix=$OPTARG
	;;
	\?)
	echo `basename $0` 'sample_name'
	exit 1
	;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$1" ]; then
	echo `basename $0` 'sample_name'
	exit 1
fi


#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var  
#-----------------------------------------------

for file in $out_prefix.realn.recal.bam $out_prefix.realn.recal.bai $out_prefix.realn.recal.bam.bai $out_prefix.summary.txt $out_prefix.dbnsfp.snpeff2gatk.vcf
do
if test -e $file; then
rename $out_prefix $1 $file #other part of the name should not have the same string as $out_prefix
fi
done

for file in .gene_summ.txt
do
if test -e $file; then
mv $file $1$file
fi
done


if test -e $out_prefix.html; then
mv $out_prefix.html $1.var.html
fi

if test -e $out_prefix.jxl.xls; then
mv $out_prefix.jxl.xls $1.var.xls
fi

if test -e .2.html; then
mv .2.html $1.var1.html
fi

if test -e .2.jxl.xls; then
mv .2.jxl.xls $1.var1.xls
fi
